home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Linux
/
Kubuntu 8.10
/
kubuntu-8.10-desktop-i386.iso
/
casper
/
filesystem.squashfs
/
lib
/
partman
/
finish.d
/
10clear_partitions
next >
Wrap
Text File
|
2008-10-29
|
3KB
|
98 lines
#! /bin/sh
# Remove critical files to ensure we don't end up with a mixed system.
. /lib/partman/lib/base.sh
failed () {
db_progress STOP
db_input critical partman-target/clear_partitions_failed || true
db_go || true
exit 1
}
count=0
partitions=$(
for dev in $DEVICES/*; do
[ -d "$dev" ] || continue
cd $dev
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
[ -f "$id/method" ] || continue
[ -f "$id/use_filesystem" ] || continue
[ -f "$id/mountpoint" ] || continue
[ "$fs" != free ] || continue
[ -f "$id/format" ] && continue
count=$(($count + 1))
mp="$(cat "$id/mountpoint")"
echo "$mp,$path"
done
close_dialog
done | sort
)
[ -n "$partitions" ] || exit 0
echo "Considering $partitions." | tr '\n' ' ' | logger -t clear_partitions
tmp="/mnt/tmpmount"
mkdir -p "$tmp"
template=partman-target/clear_partitions_progress
db_progress START 0 $count ubiquity/install/title
db_progress INFO $template
to_delete=""
for part in $partitions; do
mp="${part%,*}"
path="${part#*,}"
if [ "$mp" = "/" ]; then
mount $path $tmp || failed
for x in bin dev etc lib lib32 lib64 proc sbin usr var sys; do
[ -e "$tmp/$x" ] && (rm -rf "$tmp/$x" &&
logger -t clear_partitions "Removing $x from / ($path)." ||
failed)
done
for x in $tmp/initrd* $tmp/vmlinuz*; do
[ -e "$x" ] && (rm -rf "$x" || failed)
done
# /home could be a symlink.
[ -f "$tmp/home" ] && (rm "$tmp/home" || failed)
# / could have the wrong owner.
chown root:root $tmp
# Preserve the UID, if possible.
db_get passwd/username || true
username="$RET"
if [ -n "$username" ] && [ -d "$tmp/home/$username" ]; then
db_set passwd/user-uid "$(stat -c %u "$tmp/home/$username")" || true
db_set passwd/user-gid "$(stat -c %g "$tmp/home/$username")" || true
fi
umount $tmp
elif [ "$mp" = "/home" ]; then
mount $path $tmp || failed
# Preserve the UID, if possible.
db_get passwd/username || true
username="$RET"
if [ -n "$username" ] && [ -d "$tmp/$username" ]; then
db_set passwd/user-uid "$(stat -c %u "$tmp/$username")" || true
db_set passwd/user-gid "$(stat -c %g "$tmp/$username")" || true
fi
umount $tmp
elif echo "$mp" | egrep -q "^/usr/local" || echo "$mp" | egrep -q "^/var/local"; then
logger -t clear_partitions "Skipping $mp ($path)."
continue
else
for x in bin dev etc lib lib32 lib64 proc sbin usr var sys; do
if echo "$mp" | egrep -q "^/$x(\$|/)"; then
mount $path $tmp || failed
logger -t clear_partitions "Removing everything from $mp ($path)."
rm -rf $tmp/* || failed
umount $tmp
break
fi
done
fi
db_progress STEP 1
done
db_progress STOP
rmdir $tmp